package com.test.test;


import cn.hutool.core.util.StrUtil;

import java.io.File;
import java.util.*;
import java.util.concurrent.CompletableFuture;

public class Study {

    /**
     * 使用+拼接字符串
     */
    public static String concatenationStringByPlus(String prefix, int i) {
        return prefix + "-" + i;
    }

    /**
     * 使用StringBuilder拼接字符串
     */
    public static String concatenationStringByStringBuilder(String prefix, int i) {
        return new StringBuilder().append(prefix).append("-").append(i).toString();
    }

    /**
     * 测试使用+拼接字符串耗时
     */

    public static void testStringConcatenation01ByPlus() {
        long startTime = System.currentTimeMillis();
        int count = 100000;
        for (int i = 0; i < count; i++) {
            String str = concatenationStringByPlus("testStringConcatenation01ByStringBuilder:", i);
        }
        long endTime = System.currentTimeMillis();
        System.out.println("testStringConcatenation01ByPlus，拼接字符串" + count + "次，花费" + (endTime - startTime) + "秒");
    }


    /**
     * 测试使用StringBuilder拼接字符串耗时
     */

    public static void testStringConcatenation02ByStringBuilder() {
        long startTime = System.currentTimeMillis();
        int count = 100000;
        for (int i = 0; i < count; i++) {
            String str = concatenationStringByStringBuilder("testStringConcatenation02ByStringBuilder:", i);
        }
        long endTime = System.currentTimeMillis();
        System.out.println("testStringConcatenation02ByStringBuilder，拼接字符串" + count + "次，花费" + (endTime - startTime) + "秒");
    }


    private int binarySearch(int[] arr, int target) {
        int left = 0;
        int right = arr.length - 1;
        while (left <= right) {
            int mid = (right - left) / 2 + left;
            if (arr[mid] == target) {
                return mid;
            } else if (arr[mid] > target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        Integer integer = new Integer(1);
        int i = integer.intValue();
        Integer integer1 = Integer.valueOf(1);
        LinkedList<String> list = new LinkedList<>();
        ArrayList<String> list1 = new ArrayList<>();
        return -1;
    }


    public static boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) {
            return false;
        }
        char[] sc = s.toCharArray();
        char[] tc = t.toCharArray();
        HashMap<Character, Integer> s1 = new HashMap<>();
        HashMap<Character, Integer> t1 = new HashMap<>();
        for (int i = 0; i < sc.length; i++) {
            s1.put(sc[i], s1.getOrDefault(sc[i], 0) + 1);
        }
        for (int i = 0; i < tc.length; i++) {
            t1.put(tc[i], t1.getOrDefault(tc[i], 0) + 1);
        }
        return s1.equals(t1);
    }

    public static void main1() {
        String s = "   fly me   to   the moon  ";
        String trim = s.trim();
        int i = trim.lastIndexOf(" ");
        System.out.println(trim.length() - 1 - i);
    }

    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
    public static ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode l3 = new ListNode(0,null);
        ListNode head = l3;
        while(l1!=null || l2!=null){
            int result = l3.val+(l1==null?0:l1.val)+(l2==null?0:l2.val);
            if (result >0){
                l3.next=new ListNode(0,null);
            }
            if(result>=10){
                l3.next.val=1;
            }
            l3=new ListNode((result)%10,l3.next);
            l3=l3.next;
            if(l1!=null){
                l1=l1.next;
            }
            if(l2!=null){
                l2=l2.next;
            }
        }
        return head;
    }

    public static void main(String[] args) {
        System.out.println(3/2);
    }
}
